import Cookies from 'js-cookie'

const USER_ID = "userId";
const USER_ROLE = "userRole";
const ADMINAUTHENTICATION = "Admin-Authentication";
const PERMISSION_CODE_LIST = "permission_code_list";


export function setLoginAuthentication(val) {
  return Cookies.set(ADMINAUTHENTICATION, val);
}

export function setLoginUserId(val) {
  return Cookies.set(USER_ID, val);
}

export function setUserRole(val) {
  return Cookies.set(USER_ROLE, val)
}

export function getLoginUserId() {
  return Cookies.get(USER_ID);
}

export function getLoginAuthentication() {
  return Cookies.get(ADMINAUTHENTICATION);
}

export function getUserRole() {
  return Cookies.get(USER_ROLE);
}

export function delUserToken() {
  return Cookies.remove(ADMINAUTHENTICATION)
}

export function delUserId() {
  return Cookies.remove(USER_ID)
}

export function delUserRole() {
  return Cookies.remove(USER_ROLE)
}

export function setPermission(val) {
  return Cookies.set(PERMISSION_CODE_LIST, JSON.stringify(val));
}

export function getPermission() {
  return Cookies.get(PERMISSION_CODE_LIST);
}

export function delPermission() {
  return Cookies.remove(PERMISSION_CODE_LIST);
}

// 删除所有的登录信息
export function removeAllLoginInfo() {
  delUserToken();
  delUserId();
  delUserRole();
  delPermission();
}

// 设置登录token和登录用户ID
export function setAllLoginInfo(authentication, loginUserId) {
  setLoginAuthentication(authentication);
  setLoginUserId(loginUserId);
}
